<template>
  <BaseMainSlot>
    <template v-slot:searchbox>
      <el-collapse v-model="activeName" accordion @change="handleChange">
        <el-collapse-item name="1">
          <template slot="title">
            <div class="select-btns search-btns" @click.stop="changeSelect()">
              <i class="el-icon-circle-check"></i>
              <p v-if="activeName === '1'">收起筛选</p>
              <p v-if="activeName === ''">展开筛选</p>
            </div>
          </template>
          <div class="search-btn search-btns" @click.stop="queryPageList()">
            <i class="el-icon-circle-check"></i>
            <p>查询</p>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">疾病名称</div>
            <el-input v-model="diseaseName" clearable @change="queryPageList" />
          </div>
        </el-collapse-item>
      </el-collapse>
    </template>
    <template v-slot:btnsBar>
      <ActionBar :add-active="addActive" :del-active="delActive" :page-no="163" @add="add" @del="del" />
    </template>
    <template v-slot:content>
      <el-table ref="tableData" v-loading="loading" highlight-current-row :data="tableData" stripe border
        height="calc(100% - 50px)" :row-key="
          row => {
            return row.diseaseBankId;
          }
        " @selection-change="handleSelectionChange" @select="select" @select-all="selectAll">
        <el-table-column type="selection" width="55" :reserve-selection="true"
          :selectable="(row) => { return !row.selectable }" />
        <el-table-column type="index" label="序号" width="50">
          <template slot-scope="scoped">{{ scoped.row.diseaseBankId ? scoped.$index + 1 : '' }}</template>
        </el-table-column>
        <!-- <el-table-column prop="diseaseBankId" label="鱼塘ID" /> -->
        <el-table-column prop="diseaseName" label="疾病名称" />
        <!-- <el-table-column prop="offDrugPeriod" label="休药期(天)" /> -->
        <el-table-column prop="mainSymptoms" label="主要症状" />
        <el-table-column prop="therapeuticMethod" label="治疗方法" />
        <el-table-column label="操作" width="250">
          <template v-if="scoped.row.diseaseBankId" slot-scope="scoped">
            <div class="table-btns-box">
              <div class="table-btns edit-btns" @click="edit(scoped.row)">
                <!-- <div class="table-btns edit-btns" @click="edit(scoped.row)"  v-if="judgePermission(163,'edit')"> -->
                <p>修改</p>
              </div>
              <div class="table-btns del-btns" @click="delOne(scoped.row)">
                <!-- <div class="table-btns del-btns" @click="delOne(scoped.row)"  v-if="judgePermission(163,'deleteone')"> -->
                <p>删除</p>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <Pagination :page-size="pageSize" :current-page="currentPage" :total-size="totalSize"
        @changeCurrentPage="changeCurrentPage" />
      <AddEditDialog ref="addEditDialog" :now-chance-stau="nowChanceStau" :title-text="titleText"
        :edit-object="editObject" :show.sync="showAddEditDialog" @closeDialog="closeDialog" @cancelDialog="cancel" />
    </template>
  </BaseMainSlot>
</template>

<script>
import ActionBar from "@/components/ActionBar";
import Pagination from "@/components/Pagination";
import BaseMainSlot from "@/components/BaseMainSlot/kong-new2.vue";
import AddEditDialog from "./components/add-edit-dialog.vue";
import { mymixin } from "@/utils/mixin";
import { mapGetters } from "vuex";

import DiseaseBankApi from "@/api/basic-info-manage/diseaseBank";
export default {
  name: "WarehouseManage",
  components: { ActionBar, Pagination, BaseMainSlot, AddEditDialog },
  mixins: [mymixin],
  data() {
    return {
      // 查询条件：名称
      diseaseName: "",
      checkedIdList: []
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission"
    })
  },
  watch: {},
  created() {
    this.queryPageList();
  },
  mounted() { },
  methods: {
    queryPageList() {
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        entity: {
          diseaseName: this.diseaseName
        }
      };
      DiseaseBankApi.queryPageByCondition(params).then(res => {
        if (res.success === true) {
          let data = res.data || {};
          this.totalSize = data.totalElements;
          // 赋值数组
          this.tableData = data.content;
          this.addblankmet();
          this.resetActionBar();
        }
      });
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.queryPageList();
    },
    selectAll(list) {
      let notvalue = true;
      list.forEach(item => {
        if (!item.diseaseBankId) {
          notvalue = false;
        }
      });
      if (notvalue === false) {
        this.$message.warning("不可选择空数据！");
      }
    },
    select(list) {
      let notvalue = true;
      list.forEach(item => {
        if (!item.diseaseBankId) {
          notvalue = false;
        }
      });
      if (notvalue === false) {
        this.$message.warning("不可选择空数据！");
      }
    },
    handleSelectionChange(list) {
      this.checkedIdList = [];
      let notvalue = true;
      let emptyList = [];
      this.checkedIdList = list.map(item => {
        if (item.diseaseBankId) {
          return item.diseaseBankId;
        } else {
          notvalue = false;
          emptyList.push(item);
          return "";
        }
      });
      if (notvalue === false) {
        // this.$message.warning("不可选择空数据！");
        this.toggleNoSelection(emptyList);
        return;
      }
      if (this.checkedIdList.length >= 1) this.delActive = true;
      else this.delActive = false;
    },
    // 单个删除
    delOne(data) {
      this.$confirm("此操作将永久删除该项, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        
      })
        .then(() => {
          DiseaseBankApi.delById({ id: data.diseaseBankId }).then(res => {
            if (res.success === true) {
              this.$message.success("删除成功!");
              this.queryPageList();
              this.resetActionBar();
            }
          });
        })
        .catch(() => {
          this.resetActionBar();
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 表格删除
    delmessage() {
      DiseaseBankApi.delListById({ idList: this.checkedIdList }).then(res => {
        if (res.success) {
          this.$message.success("删除成功");
          this.queryPageList();
          this.resetActionBar();
        }
      });
    },
    // 添加
    add() {
      this.nowChanceStau = "add";
      this.titleText = "添加";
      this.addActive = false;
      this.delActive = false;
      this.showAddEditDialog = true;
    },
    // 修改
    edit(row) {
      if (row.diseaseBankId) {
        this.editObject = JSON.parse(JSON.stringify(row));
        this.nowChanceStau = "edit";
        this.titleText = "修改";
        this.addActive = false;
        this.delActive = false;
        this.showAddEditDialog = true;
      } else {
        this.editObject = {};
      }
    }
  }
};
</script>

<style lang="scss" scoped></style>
